package at.fhooe.mc.duel_game;

import java.util.List;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

public class DeviceArrayAdapter extends ArrayAdapter<DeviceItem> implements OnClickListener {

	List<DeviceItem> deviceList;

	public DeviceArrayAdapter(Context context, int textViewResourceId,
			List<DeviceItem> objects) {
		super(context, textViewResourceId, objects);

		deviceList = objects;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		// TODO Auto-generated method stub
		if (convertView == null) {
			Context c = getContext();
			LayoutInflater inflater = (LayoutInflater) c
					.getSystemService(Context.LAYOUT_INFLATER_SERVICE);

			convertView = inflater.inflate(R.layout.layout_device, null);
			//convertView.setOnClickListener(this);
		}

		DeviceItem data = deviceList.get(position);

		if (data != null) {
			TextView v = (TextView) convertView
					.findViewById(R.id.textViewListViewDeviceName);
			v.setText(data.getName());

			v = (TextView) convertView.findViewById(R.id.textViewListViewMac);
			v.setText(data.getMac());

			ImageView image = (ImageView) convertView
					.findViewById(R.id.imageViewListViewDevice);
			image.setImageResource(data.getImageId());
		}

		return convertView;
	}

	public void onClick(View v) {
		switch (v.getId()) {
		default:
			Toast.makeText(getContext(), "Item clicked", 2000).show();
			break;
		}
	}
}
